<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<title>添加电影</title>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
		<title>首页</title>

		<!-- Bootstrap -->
		<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
		<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
		<script src="js/jquery.min.js"></script>
		<script src="js/jquery.cookie.js" type="text/javascript" charset="utf-8"></script>
		
		<!-- Include all compiled plugins (below), or include individual files as needed -->
		<script src="bootstrap/js/bootstrap.min.js"></script>

		<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
		<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
		<!--[if lt IE 9]>
      <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
	</head>

	<body>
		<div class="container  text-center">
			<div class="row">
				<div class="col-lg-12">
					<a href="index.html">查看所有</a>
				</div>

				<form id="add" action="filminfo" method="post">
					<p>
						<input type="text" class="form-control" name="filmName" id="filmName" placeholder="电影名称">
					</p>
					<p>
						<select class="form-control" id="typeId" name="typeId">
							<option value="">选择类型</option>
						</select>

					</p>

					<p>
						<input type="text" class="form-control" name="actor" id="actor" placeholder="主演">
					</p>
					<p>
						<input type="text" class="form-control" name="director" id="director" placeholder="导演">
					</p>
					<p>
						<input type="text" class="form-control" name="ticketPrice" id="ticketPrice" placeholder="价格">
					</p>

					<input class="btn btn-default" type="button" value="提交" onclick="if(confirm('确认添加？')){register()}" />
				</form>

			</div>
		</div>

		<script type="text/javascript">
			/* 根据类型的id查类型 */
			$.ajax({
				type: "get",
				dataType: "json",
				async: false,
				url: "filmtypes?token=" + $.cookie("token"),
				success: function(msg2) {

					for(var i = 0; i < msg2.length; i++) {
						$("#typeId").append("<option value='" + msg2[i].typeId + "'>" + msg2[i].typeName + "</option>");
					}

					typeName = msg2.typeName;
				},
				error: function() {
					alert("连接失败");
				}

			});
		</script>
		<script type="text/javascript">
			function register() {
				var post_data = {
					"typeId": $("#typeId").val(),
					"filmName": $("#filmName").val(),
					"actor": $("#actor").val(),
					"director": $("#director").val(),
					"ticketPrice": $("#ticketPrice").val()
				};
				$.ajax({
					cache: false,
					type: "post",
					contentType: "application/json; charset=utf-8",
					url: "filminfo?token=" + $.cookie("token"),
					data: JSON.stringify(post_data),
					async: false,
					error: function(request) {
						alert("添加失败");
					},
					success: function(data) {
						alert("添加成功");
						location.href="index.html";
					}
				});
			}
		</script>
	</body>

</html>